package com.fdb.efp.nls.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.ColltWriteOffAppDao;
import com.fdb.efp.nls.service.domain.ColltWriteOffApp;
import com.fdb.efp.nls.service.facade.ColltWriteOffAppService;
import com.fdb.efp.nls.service.vo.ColltWriteOffAppVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Service Impl: 核销申请表服务实现
 * @author ligm
 * @date 2019-08-27
 */
@Service("colltWriteOffAppService")
public class ColltWriteOffAppServiceImpl implements ColltWriteOffAppService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(ColltWriteOffAppServiceImpl.class);

	@Autowired
	private ColltWriteOffAppDao colltWriteOffAppDao;

	@Override
	public int insertColltWriteOffApp(ColltWriteOffAppVO colltWriteOffAppVo) {
		logger.debug("当前新增数据为:"+ colltWriteOffAppVo.toString());
		int num = 0;
		try {
			ColltWriteOffApp colltWriteOffApp = new ColltWriteOffApp();
			beanCopy(colltWriteOffAppVo, colltWriteOffApp);
			num = colltWriteOffAppDao.insertColltWriteOffApp(colltWriteOffApp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	@Override
	public int deleteByPk(ColltWriteOffAppVO colltWriteOffAppVo) {
		logger.debug("当前删除数据条件为:"+ colltWriteOffAppVo);
		int num = 0;
		try {
			ColltWriteOffApp colltWriteOffApp = new ColltWriteOffApp();
			beanCopy(colltWriteOffAppVo, colltWriteOffApp);
			num = colltWriteOffAppDao.deleteByPk(colltWriteOffApp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ colltWriteOffAppVo +"删除的数据条数为"+ num);
		return num;
	}

	@Override
	public int updateByPk(ColltWriteOffAppVO colltWriteOffAppVo) {
		logger.debug("当前修改数据为:"+ colltWriteOffAppVo.toString());
		int num = 0;
		try {
			ColltWriteOffApp colltWriteOffApp = new ColltWriteOffApp();
			beanCopy(colltWriteOffAppVo, colltWriteOffApp);
			num = colltWriteOffAppDao.updateByPk(colltWriteOffApp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ colltWriteOffAppVo +"修改的数据条数为"+ num);
		return num;
	}

	@Override
	public int updateByCondition(ColltWriteOffAppVO colltWriteOffAppVo) {
		logger.debug("当前修改数据为:"+ colltWriteOffAppVo.toString());
		int num = 0;
		try {
			ColltWriteOffApp colltWriteOffApp = new ColltWriteOffApp();
			beanCopy(colltWriteOffAppVo, colltWriteOffApp);
			num = colltWriteOffAppDao.updateByCondition(colltWriteOffApp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ colltWriteOffAppVo +"修改的数据条数为"+ num);
		return num;
	}

	@Override
	public List<ColltWriteOffAppVO> queryByPk(ColltWriteOffAppVO colltWriteOffAppVo) {
		logger.debug("当前查询参数信息为:"+ colltWriteOffAppVo);
		try {
			ColltWriteOffApp colltWriteOffApp = new ColltWriteOffApp();
			beanCopy(colltWriteOffAppVo, colltWriteOffApp);
			List<ColltWriteOffApp> queryRsl = colltWriteOffAppDao.queryByPk(colltWriteOffApp);
			if (Objects.nonNull(queryRsl)) {
				List<ColltWriteOffAppVO> resultList = (List<ColltWriteOffAppVO>) beansCopy(queryRsl, ColltWriteOffAppVO.class);
				ColltWriteOffAppVO out = beanCopy(queryRsl, new ColltWriteOffAppVO());
				logger.debug("当前查询结果为:"+ out.toString());
				return resultList;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@Override
	public List<ColltWriteOffAppVO> queryByPkByPage(ColltWriteOffAppVO colltWriteOffAppVo) {
		logger.debug("当前查询参数信息为:"+ colltWriteOffAppVo);
		try {
			ColltWriteOffApp colltWriteOffApp = new ColltWriteOffApp();
			beanCopy(colltWriteOffAppVo, colltWriteOffApp);
			List<ColltWriteOffApp> queryRsl = colltWriteOffAppDao.queryByPkByPage(colltWriteOffApp);
			if (Objects.nonNull(queryRsl)) {
				List<ColltWriteOffAppVO> resultList = (List<ColltWriteOffAppVO>) beansCopy(queryRsl, ColltWriteOffAppVO.class);
				ColltWriteOffAppVO out = beanCopy(queryRsl, new ColltWriteOffAppVO());
				logger.debug("当前查询结果为:"+ out.toString());
				return resultList;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@Override
	public List<ColltWriteOffAppVO> queryAllOwner(ColltWriteOffAppVO colltWriteOffAppVo) {
		logger.info("当前查询参数信息为:" + JSONObject.toJSONString(colltWriteOffAppVo));
		if(Objects.isNull(colltWriteOffAppVo)){
			return null;
		}
		try {
			List<ColltWriteOffApp> dataList = colltWriteOffAppDao.queryAllOwnerByPage(colltWriteOffAppVo);
			if (Objects.nonNull(dataList)) {
				pageSet(dataList, colltWriteOffAppVo);
				List<ColltWriteOffAppVO> resultList = new ArrayList<ColltWriteOffAppVO>();
				resultList = (List<ColltWriteOffAppVO>) beansCopy(dataList, ColltWriteOffAppVO.class);
				return resultList;
			} else {
				logger.info("查询结果为空！");
			}
		} catch (Exception e) {
			logger.error("查询发生异常！", e);
		}
		return null;
	}

	@Override
	public List<ColltWriteOffAppVO> queryAllCurrOrg(ColltWriteOffAppVO colltWriteOffAppVo) {
		logger.info("当前查询参数信息为:" + JSONObject.toJSONString(colltWriteOffAppVo));
		if(Objects.isNull(colltWriteOffAppVo)){
			return null;
		}
		try {
			List<ColltWriteOffApp> dataList = colltWriteOffAppDao.queryAllCurrOrgByPage(colltWriteOffAppVo);
			if (Objects.nonNull(dataList)) {
				pageSet(dataList, colltWriteOffAppVo);
				List<ColltWriteOffAppVO> resultList = new ArrayList<ColltWriteOffAppVO>();
				resultList = (List<ColltWriteOffAppVO>) beansCopy(dataList, ColltWriteOffAppVO.class);
				return resultList;
			} else {
				logger.info("查询结果为空！");
			}
		} catch (Exception e) {
			logger.error("查询发生异常！", e);
		}
		return null;
	}

	@Override
	public List<ColltWriteOffAppVO> queryAllCurrDownOrg(ColltWriteOffAppVO colltWriteOffAppVo) {
		logger.info("当前查询参数信息为:" + JSONObject.toJSONString(colltWriteOffAppVo));
		if(Objects.isNull(colltWriteOffAppVo)){
			return null;
		}
		try {
			List<ColltWriteOffApp> dataList = colltWriteOffAppDao.queryAllCurrDownOrgByPage(colltWriteOffAppVo);
			if (Objects.nonNull(dataList)) {
				pageSet(dataList, colltWriteOffAppVo);
				List<ColltWriteOffAppVO> resultList = new ArrayList<ColltWriteOffAppVO>();
				resultList = (List<ColltWriteOffAppVO>) beansCopy(dataList, ColltWriteOffAppVO.class);
				return resultList;
			} else {
				logger.info("查询结果为空！");
			}
		} catch (Exception e) {
			logger.error("查询发生异常！", e);
		}
		return null;
	}

	@Override
	public List<ColltWriteOffAppVO> queryAllCurrOwnerPrd(ColltWriteOffAppVO colltWriteOffAppVo) {
		logger.info("当前查询参数信息为:" + JSONObject.toJSONString(colltWriteOffAppVo));
		if(Objects.isNull(colltWriteOffAppVo)){
			return null;
		}
		try {
			List<ColltWriteOffApp> dataList = colltWriteOffAppDao.queryAllCurrOwnerPrdByPage(colltWriteOffAppVo);
			if (Objects.nonNull(dataList)) {
				pageSet(dataList, colltWriteOffAppVo);
				List<ColltWriteOffAppVO> resultList = new ArrayList<ColltWriteOffAppVO>();
				resultList = (List<ColltWriteOffAppVO>) beansCopy(dataList, ColltWriteOffAppVO.class);
				return resultList;
			} else {
				logger.info("查询结果为空！");
			}
		} catch (Exception e) {
			logger.error("查询发生异常！", e);
		}
		return null;
	}

	@Override
	public List<ColltWriteOffAppVO> queryAllByCondition(ColltWriteOffAppVO colltWriteOffAppVo) {
		logger.info("当前查询参数信息为:" + JSONObject.toJSONString(colltWriteOffAppVo));
		if(Objects.isNull(colltWriteOffAppVo)){
			return null;
		}
		try {
			List<ColltWriteOffApp> dataList = colltWriteOffAppDao.queryAllByCondition(colltWriteOffAppVo);
			if (Objects.nonNull(dataList)) {
				List<ColltWriteOffAppVO> resultList = new ArrayList<ColltWriteOffAppVO>();
				resultList = (List<ColltWriteOffAppVO>) beansCopy(dataList, ColltWriteOffAppVO.class);
				return resultList;
			} else {
				logger.info("查询结果为空！");
			}
		} catch (Exception e) {
			logger.error("查询发生异常！", e);
		}
		return null;
	}
}
